package com.gel.codegeneration.core.saver;

import com.gel.codegeneration.ai.model.entity.MultiFileResult;
import com.gel.codegeneration.ai.model.enums.CodeGenTypeEnum;
import com.gel.codegeneration.common.enums.ErrorCode;
import com.gel.codegeneration.convention.exception.BusinessException;

/**
 * @BelongsProject: code-generation-platform
 * @BelongsPackage: com.gel.codegeneration.core.saver
 * @Author: gel
 * @CreateTime: 2025-08-22  16:09
 * @Description: TODO 多文件代码保存模板
 * @Version: 1.0
 */
public class MultiFileCodeFileSaveTemplate extends  CodeFileSaveTemplate<MultiFileResult>{
    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    @Override
    protected void saveFile(MultiFileResult multiFileResult, String dirPath) {

        writeFile(multiFileResult.getHtmlCode(), dirPath, "index.html");
        writeFile(multiFileResult.getCssCode(), dirPath, "style.css");
        writeFile(multiFileResult.getJsCode(), dirPath, "script.js");
    }
    @Override
    protected  void validateInput(MultiFileResult multiFileResult) {
        if(multiFileResult == null){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"代码内容不能为空");
        }

    }

}